<?php
//Use Session air times
$ATQuery = "SELECT * from $airtimes_Table ORDER BY military";
$resultAT = $db->getAll($ATQuery, DB_FETCHMODE_ASSOC);
if (DB::isError($resultAT)) {
	die ($resultAT->getMessage());
}
			
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						//BEGIN JAVASCRIPT FUNCTION TO NULL UNUSED DAYS ACCORDING TO AIRTIMES
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						echo"<script language=\"JavaScript\" type=\"text/javascript\">
						<!--
						//Array to hold days and values
						
						function timeEntry(time,mon,tue,wed,thu,fri,sat,sun){
						this.time = time;
						this.mon = mon;
						this.tue = tue;
						this.wed = wed;
						this.thu = thu;
						this.fri = fri;
						this.sat = sat;
						this.sun = sun;
						}
						
						var javaAT = new Array(" . count($resultAT) . ");
						";
						
						
						$a = 0;
						while($a < count($resultAT)){
						echo "javaAT[$a] = new timeEntry(\"".$resultAT[$a]['military']."\",\"".$resultAT[$a][mon]."\",\"".$resultAT[$a][tue]."\",\"".$resultAT[$a][wed]."\",\"".$resultAT[$a][thu]."\",\"".$resultAT[$a][fri]."\",\"".$resultAT[$a][sat]."\",\"".$resultAT[$a][sun]."\");\n";
						++$a;
						}
						
						echo"function enableSwitch(day){
							document.MyPopUp.switchyo.disabled = false;
							document.MyPopUp.copyyo.disabled = false;
							document.MyPopUp.update.disabled = false;
							document.MyPopUp.deleteyo.disabled = false;

							var dropDown = eval(\"document.MyPopUp.time.value\");
													
								for (var q=0; q < document.MyPopUp.elements.length; q++) {

								 // get each element of form form
								 var e = document.MyPopUp.elements[q];
								 originalMoveDay = e.name;
								 
								 if(e.type.indexOf(\"checkbox\") == -1 ){
									continue;// not a checkbox
								}else if(e.checked == true && originalMoveDay == day){
									//do nothing
								}else{
									e.checked = false;
								}
							}//END figure out which day is checked
							
							
					//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				
							//BEGIN Determine if the new entry day and Time have already been used in Moves Array
							var arrayDay = \"\";
							
							for (var q=0; q < movesArray.length; q++) {
								//figure out what array day is true
								if(movesArray[q].time == dropDown && movesArray[q].mon == true && day == \"mon\"){
									alert(\"You have already scheduled a spot for Monday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(movesArray[q].time == dropDown && movesArray[q].tue == true && day == \"tue\"){
									alert(\"You have already scheduled a spot for Tuesday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(movesArray[q].time == dropDown && movesArray[q].wed == true && day == \"wed\"){
									alert(\"You have already scheduled a spot for Wednesday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(movesArray[q].time == dropDown && movesArray[q].thu == true && day == \"thu\"){
									alert(\"You have already scheduled a spot for Thursday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(movesArray[q].time == dropDown && movesArray[q].fri == true && day == \"fri\"){
									alert(\"You have already scheduled a spot for Friday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(movesArray[q].time == dropDown && movesArray[q].sat == true && day == \"sat\"){
									alert(\"You have already scheduled a spot for Saturday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(movesArray[q].time == dropDown && movesArray[q].sun == true && day == \"sun\"){
									alert(\"You have already scheduled a spot for Sunday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}
							
								
							}//end loop
							
							//END Determine if the new entry day and Time have already been used
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++		
						
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				
							//BEGIN Determine if the new entry day and Time have already been used in Copy Array
							var arrayDay = \"\";
							
							for (var q=0; q < copyArray.length; q++) {
								//figure out what array day is true
								if(copyArray[q].time == dropDown && copyArray[q].mon == true && day == \"mon\"){
									alert(\"You have already scheduled a spot for Monday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(copyArray[q].time == dropDown && copyArray[q].tue == true && day == \"tue\"){
									alert(\"You have already scheduled a spot for Tuesday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(copyArray[q].time == dropDown && copyArray[q].wed == true && day == \"wed\"){
									alert(\"You have already scheduled a spot for Wednesday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(copyArray[q].time == dropDown && copyArray[q].thu == true && day == \"thu\"){
									alert(\"You have already scheduled a spot for Thursday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(copyArray[q].time == dropDown && copyArray[q].fri == true && day == \"fri\"){
									alert(\"You have already scheduled a spot for Friday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(copyArray[q].time == dropDown && copyArray[q].sat == true && day == \"sat\"){
									alert(\"You have already scheduled a spot for Saturday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(copyArray[q].time == dropDown && copyArray[q].sun == true && day == \"sun\"){
									alert(\"You have already scheduled a spot for Sunday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}
							
								
							}//end loop
							
							//END Determine if the new entry day and Time have already been used in Copy Array
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
						
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				
							//BEGIN Determine if the new entry day and Time have already been used in Update Array
							var arrayDay = \"\";
							
							for (var q=0; q < updateArray.length; q++) {
								//figure out what array day is true
								if(updateArray[q].time == dropDown && updateArray[q].mon == true && day == \"mon\"){
									alert(\"You have already scheduled a spot for Monday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(updateArray[q].time == dropDown && updateArray[q].tue == true && day == \"tue\"){
									alert(\"You have already scheduled a spot for Tuesday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(updateArray[q].time == dropDown && updateArray[q].wed == true && day == \"wed\"){
									alert(\"You have already scheduled a spot for Wednesday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(updateArray[q].time == dropDown && updateArray[q].thu == true && day == \"thu\"){
									alert(\"You have already scheduled a spot for Thursday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(updateArray[q].time == dropDown && updateArray[q].fri == true && day == \"fri\"){
									alert(\"You have already scheduled a spot for Friday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(updateArray[q].time == dropDown && updateArray[q].sat == true && day == \"sat\"){
									alert(\"You have already scheduled a spot for Saturday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(updateArray[q].time == dropDown && updateArray[q].sun == true && day == \"sun\"){
									alert(\"You have already scheduled a spot for Sunday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}
							
								
							}//end loop
							
							//END Determine if the new entry day and Time have already been used in Update Array
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
						
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
				
							//BEGIN Determine if the new entry day and Time have already been used in Delete Array
							var arrayDay = \"\";
							
							for (var q=0; q < deleteArray.length; q++) {
								//figure out what array day is true
								if(deleteArray[q].time == dropDown && deleteArray[q].mon == true && day == \"mon\"){
									alert(\"You have already scheduled a spot for Monday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(deleteArray[q].time == dropDown && deleteArray[q].tue == true && day == \"tue\"){
									alert(\"You have already scheduled a spot for Tuesday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(deleteArray[q].time == dropDown && deleteArray[q].wed == true && day == \"wed\"){
									alert(\"You have already scheduled a spot for Wednesday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(deleteArray[q].time == dropDown && deleteArray[q].thu == true && day == \"thu\"){
									alert(\"You have already scheduled a spot for Thursday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(deleteArray[q].time == dropDown && deleteArray[q].fri == true && day == \"fri\"){
									alert(\"You have already scheduled a spot for Friday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(deleteArray[q].time == dropDown && deleteArray[q].sat == true && day == \"sat\"){
									alert(\"You have already scheduled a spot for Saturday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}else if(deleteArray[q].time == dropDown && deleteArray[q].sun == true && day == \"sun\"){
									alert(\"You have already scheduled a spot for Sunday at this time slot!\");
									document.MyPopUp.switchyo.disabled = true;
									document.MyPopUp.copyyo.disabled = true;
									document.MyPopUp.update.disabled = true;
									document.MyPopUp.deleteyo.disabled = true;
								}
							
								
							}//end loop
							
							//END Determine if the new entry day and Time have already been used in DELETE Array
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++								
											
						}";
					
						echo "function nullDays(){
						var dropDown = eval(\"document.MyPopUp.time.value\");
						
									document.MyPopUp.switchyo.disabled = false;
									document.MyPopUp.copyyo.disabled = false;
									document.MyPopUp.update.disabled = false;
									document.MyPopUp.deleteyo.disabled = false;
						
						
						for (var q=0; q < document.MyPopUp.elements.length; q++) {

								 // get each element of form form
								 var e = document.MyPopUp.elements[q];
								 originalMoveDay = e.name;
								 
								 if(e.type.indexOf(\"checkbox\") == -1 ){
									continue;// not a checkbox
								}else if(e.checked == true){
									enableSwitch(originalMoveDay);
								}else{
									e.checked = false;
								}
							}//END figure out which day is checked
							
						
						
						
						
						for (var q=0; q <".count($resultAT)."; q++) {
							if(dropDown == javaAT[q].time){						
						
							
								if(javaAT[q].mon != 'true'){
								var mon = \"document.MyPopUp.mon.checked = false\";
								eval(mon);
								var mon = \"document.MyPopUp.mon.disabled = true\";
								eval(mon);
								}else{
								var mon = \"document.MyPopUp.mon.disabled = false\";
								eval(mon);	
								}
								
								if(javaAT[q].tue != 'true'){
								var tue = \"document.MyPopUp.tue.checked = false\";
								eval(tue);								
								var tue = \"document.MyPopUp.tue.disabled = true\";
								eval(tue);
								}else{
								var tue = \"document.MyPopUp.tue.disabled = false\";
								eval(tue);	
								}								
								
								if(javaAT[q].wed != 'true'){
								var wed = \"document.MyPopUp.wed.checked = false\";
								eval(wed);								
								var wed = \"document.MyPopUp.wed.disabled = true\";
								eval(wed);
								}else{
								var wed = \"document.MyPopUp.wed.disabled = false\";
								eval(wed);	
								}								
									
								if(javaAT[q].thu != 'true'){
								var thu = \"document.MyPopUp.thu.checked = false\";
								eval(thu);								
								var thu = \"document.MyPopUp.thu.disabled = true\";
								eval(thu);
								}else{
								var thu = \"document.MyPopUp.thu.disabled = false\";
								eval(thu);	
								}								
								
								if(javaAT[q].fri != 'true'){
								var fri = \"document.MyPopUp.fri.checked = false\";
								eval(fri);								
								var fri = \"document.MyPopUp.fri.disabled = true\";
								eval(fri);
								}else{
								var fri = \"document.MyPopUp.fri.disabled = false\";
								eval(fri);	
								}								
									
								if(javaAT[q].sat != 'true'){
								var sat = \"document.MyPopUp.sat.checked = false\";
								eval(sat);								
								var sat = \"document.MyPopUp.sat.disabled = true\";
								eval(sat);
								}else{
								var sat = \"document.MyPopUp.sat.disabled = false\";
								eval(sat);	
								}							
									
								if(javaAT[q].sun != 'true'){
								var sun = \"document.MyPopUp.sun.checked = false\";
								eval(sun);								
								var sun = \"document.MyPopUp.sun.disabled = true\";
								eval(sun);
								}else{
								var sun = \"document.MyPopUp.sun.disabled = false\";
								eval(sun);	
								}							
						break;
							}
						}	 

						//alert(javaAT[10].time);
						//alert(mon);
						}
						//-->
						</script>";
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
						//END JAVASCRIPT FUNCTION TO NULL UNUSED DAYS ACCORDING TO AIRTIMES
						//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 

echo "<DIV onclick='event.cancelBubble = true;' class=\"popup\" id=\"spotInfo\" onMouseUp=\"captureY();\">\n
		<TABLE width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\">\n
		
		<tr>
  <td id=\"titleBar\" style=\"cursor:move; background-color:#999999;\" width=\"100%\" align=\"right\">
  <ilayer width=\"100%\" onSelectStart=\"return false\">

  <layer width=\"100%\" onMouseover=\"isHot=true;if (isN4) ddN4(spotInfo)\" onMouseout=\"isHot=false\">
  <TABLE width=\"100%\" style='background-image:url(images/SwitchBoard-1.gif); background-position:right; background-repeat:no-repeat;'><TR><TD align=\"left\" style=\"font-size:10px; font-weight:600; color:#000000; text-decoration:underline;\">CLICK TO DRAG:</TD></TR></TABLE>
  
  </layer> 
  </ilayer>
 
  </td>

  </tr>
		<FORM action=\"formaction.php\" method=\"post\" name=\"MyPopUp\">
		<TR><TD>\n
			<TABLE id='detailsTable' width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" bgcolor=\"#000000\">\n
				<TR><TD class=\"popupHeaders\" width=\"15%\">Client:</TD><TD><DIV class=\"popupdata\" id=\"uw\"></DIV></TD></TR>
				<TR><TD class=\"popupHeaders\" width=\"15%\">Spot:</TD><TD><DIV class=\"popupdata\" id=\"spot\"></DIV></TD></TR>
				<TR><TD class=\"popupHeaders\" width=\"15%\">Rate:</TD><TD><DIV class=\"popupdata\" id=\"rate\"></DIV></TD></TR>
				<TR><TD class=\"popupHeaders\" width=\"15%\">Dates:</TD><TD><DIV class=\"popupdata\" id=\"date\"></DIV></TD></TR>
				<TR><TD class=\"popupHeaders\" width=\"15%\">Type:</TD><TD><DIV class=\"popupdata\" id=\"type\"></DIV></TD></TR>
				<TR><TD class=\"popupHeaders\" width=\"15%\">Length:</TD><TD><DIV class=\"popupdata\" id=\"SpotLength\"></DIV></TD></TR>
			</TABLE>
		</TD></TR>\n
		
			<TR>\n";
			echo"<TD align=\"center\">\n";
				echo("<input name=\"copyyo\" type=\"button\" class=\"inputButton\"  value=\"Copy To:\" onClick=\"addCopy()\">&nbsp;");
				echo("<input name=\"switchyo\" type=\"button\" class=\"inputButton\"  value=\"Move To:\" onClick=\"addMove()\">&nbsp;<select name=\"time\" size=\"1\" onChange=\"nullDays()\"> \n");
							echo("<option value=\"not_selected\" selected>Choose</option> \n");   
							$r=0;
							while ($r < count($resultAT)) {
								$hour = $resultAT[$r]['hour']; 
								$minute = $resultAT[$r]['minute'];
								$seconds = $resultAT[$r]['seconds'];
								$ampm = $resultAT[$r]['ampm'];
								$military = $resultAT[$r]['military'];
								echo("<option value=\"$military\">$hour:$minute:$seconds $ampm</option> \n");   
								++$r;
							}//END Loop
					echo("</SELECT> \n \n");
					//Day of week check boxes
					echo"<BR><INPUT name=\"mon\" type=\"checkbox\" value=\"true\" onClick=\"enableSwitch('mon')\"><FONT size=\"-2\" color=\"#000000\">M &nbsp;</FONT>
					<INPUT name=\"tue\" type=\"checkbox\" value=\"true\" onClick=\"enableSwitch('tue')\"><FONT size=\"-2\" color=\"#000000\">T &nbsp;</FONT>
					<INPUT name=\"wed\" type=\"checkbox\" value=\"true\" onClick=\"enableSwitch('wed')\"><FONT size=\"-2\" color=\"#000000\">W &nbsp;</FONT>
					<INPUT name=\"thu\" type=\"checkbox\" value=\"true\" onClick=\"enableSwitch('thu')\"><FONT size=\"-2\" color=\"#000000\">Th &nbsp;</FONT>
					<INPUT name=\"fri\" type=\"checkbox\" value=\"true\" onClick=\"enableSwitch('fri')\"><FONT size=\"-2\" color=\"#000000\">F &nbsp;</FONT>
					<INPUT name=\"sat\" type=\"checkbox\" value=\"true\" onClick=\"enableSwitch('sat')\"><FONT size=\"-2\" color=\"#000000\">Sa &nbsp;</FONT>
					<INPUT name=\"sun\" type=\"checkbox\" value=\"true\" onClick=\"enableSwitch('sun')\"><FONT size=\"-2\" color=\"#000000\">Su &nbsp;</FONT>";
					
					
										
				echo"</TD>\n";
	  echo"</TR>\n
			
			<TR>\n
				<TD align=\"center\" bgcolor=\"#666666\"><input name=\"update\" type=\"button\" class=\"inputButton\"  value=\"Update Spot\" onClick=\"addUpdate()\">&nbsp; &nbsp; <input name=\"close\" type=\"button\" class=\"inputButton\"  value=\"Close\" onClick=\"hideCurrentPopup()\">&nbsp; &nbsp; <input name=\"deleteyo\" type=\"button\" class=\"inputButton\"  value=\"Delete Spot\" onClick=\"addDelete()\"></TD>\n
			</TR>\n
			</FORM>
		</TABLE>\n
	</DIV>\n\n";
?>


							